#include "Menu.h"
#include "RessourceManager.h"
#include <iterator>

Menu::Menu(Application* app) : Engine(app)
{
    //ctor
}

void Menu::onLaunch()
{
    Engine::onLaunch();
}

void Menu::onTick()
{
    for(std::list<Widget*>::iterator it = widgets.begin(); it != widgets.end(); ++it)
        (*it)->onTick();
}

void Menu::onRender(sf::RenderWindow* win)
{
    win->draw(background);
    for(std::list<Widget*>::iterator it = widgets.begin(); it != widgets.end(); ++it)
        (*it)->onRender(win);

}

void Menu::onEvent(sf::Event* e)
{
    for(std::list<Widget*>::iterator it = widgets.begin(); it != widgets.end(); ++it)
        (*it)->onEvent(e);
}

void Menu::onClose()
{

}

void Menu::addWidget(Widget* wid)
{
    widgets.push_back(wid);
}

void Menu::removeWidget(Widget* wid)
{
    widgets.remove(wid);
}

void Menu::setBackgroundImage(std::string image)
{
    background.setTexture(*RessourceManager::getTexture(image));
}

void Menu::onButtonPressed(WidgetButton* button)
{

}

Menu::~Menu()
{
    for(std::list<Widget*>::iterator it = widgets.begin(); it != widgets.end(); ++it)
        delete *it;
}
